from recording import save_recod_local
from save_decibel import save_to_sqlite3
from multiprocessing import Process, Queue, freeze_support
import time
from config import *
import init
from realtime_audio import audio_decibels

def main():
    message = Queue()
    start_time = str(time.strftime("%Y%m%d_%H%M%S", time.localtime()))
    init.check_mic()
    init.check_disk()
    init.create_folder(f'data/recod_{start_time}')
    init.create_table(start_time)

    # 实时分贝数据
    p1 = Process(target=audio_decibels, args=(message,))
    p1.start()

    # 分贝数据库
    p2 = Process(target=save_to_sqlite3, args=(message, 'db_table' + start_time, SAVE_SECONDS))
    p2.start()

    # 录音文件
    p3 = Process(target=save_recod_local, args=(start_time, RECORD_SECONDS,))
    p3.start()


if __name__ == '__main__':
    freeze_support()
    main()